const Service = require('egg').Service;
class LoginService extends Service {
    async Login(username) {
        try {
            let name = await this.app.model.Username.findAll({ where: { name: username.name, password: username.password } })
            return {
                code: 200,
                msg: '查询成功',
                data:name
            };
        } catch {
            return "错误"
        }
    }
    async create(username) {
        try {
            await this.app.model.Username.create({
                name: username.name,
                password: username.password
            })
            return {
                code: 200,
                msg: '添加成功',
                data:''
            }
        } catch {
            return {
                code: 501,
                msg: '添加失败'
            }
        }
    }
    async update(username) {
        try {
            await this.app.model.Username.update(
                {
                    name: username.name,
                    password: username.password
                },
                {where:{name:username.jname}}
            )
            return {
                code:200,
                msg:'修改成功',
                data:''
            }
        } catch {
            return {
                code: 501,
                msg: '修改失败',
            }
        }
    }
    async destroy(username){
        try{
            await this.app.model.Username.destroy({
                where:{name:username}
            })
            return {
                code: 200,
                msg: '删除成功',
                data:await this.app.model.Username.findAll()
            }
        }catch{
            return {
                code: 501,
                msg: '删除失败',
            }
        }
    }
}
module.exports = LoginService;